﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace POVRay {
    [PRBlock("pigment")]
    public abstract class Pattern : Pigment {
        [PRParam("turbulence")]
        public Vector3? Turbulence { get; set; }

        [PRParam("noise_generator")]
        [PRParamIntMap((int)NoiseGenerator.POV_Ray_3_1, "1")]
        [PRParamIntMap((int)NoiseGenerator.POV_Ray_3_1_RangeCorrected, "2")]
        [PRParamIntMap((int)NoiseGenerator.PerlinNoise, "3")]
        public NoiseGenerator? Noise { get; set; }

        [PRParam("octaves")]
        public int? Octaves { get; set; }

        [PRParam("omega")]
        public int? Omega { get; set; }

        [PRParam("lambda")]
        public int? Lambda { get; set; }

        //TODO: warp http://www.povray.org/documentation/view/3.6.0/407/

        [PRParam("frequency")]
        public float? Frequency { get; set; }

        [PRParam("phase")]
        public float? Phase { get; set; }

        [PRParam()]
        public Waveform Waveform { get; set; }

        protected override String GeneralParameters(int level) {
            StringBuilder sb = new StringBuilder();

            if (Frequency.HasValue) sb.Append(Scene.Indentation(level) + "frequency " + Frequency.Value.POVRayString());
            if (Phase.HasValue) sb.Append(Scene.Indentation(level) + "phase " + Phase.Value.POVRayString());
            if (Turbulence.HasValue) sb.Append(Scene.Indentation(level) + "turbulence " + Turbulence.Value.ToString());
            if (Noise.HasValue) sb.Append(Scene.Indentation(level) + "noise_generator " + ((int)Noise.Value).POVRayString());
            if (Octaves.HasValue) sb.Append(Scene.Indentation(level) + "octaves " + Octaves.Value.POVRayString());
            if (Omega.HasValue) sb.Append(Scene.Indentation(level) + "omega " + Omega.Value.POVRayString());
            if (Lambda.HasValue) sb.Append(Scene.Indentation(level) + "lambda " + Lambda.Value.POVRayString());
            if (Waveform != null) sb.Append(Scene.Indentation(level) + Waveform.POVRayString(level));

            sb.Append(base.GeneralParameters(level));

            return sb.ToString();
        }

        public override string ToString(int level) {
            return this.POVRayString(level);
        }
    }
}
